<?php

namespace App\Api;

use App\Http\Controllers\Controller;
use App\Models\Swiper;
use Illuminate\Http\Request;

class SwiperController extends Controller
{

    public function index()
    {
        $swiperes = Swiper::all();
        return $swiperes;
    }

    public function store(Request $request)
    {
        $request->validate([
            'title' => ['required'],
            'image' => ['required'],
            'url' => ['required'],
        ], [
            'title.required' => '请输入标题',
            'image.required' => '请上传图片',
            'url.required' => '请输入跳转链接'
        ]);
        Swiper::create($request->input());
        return $this->message('添加成功');
    }


    public function show(Swiper $swiper)
    {
        return $swiper;
    }


    public function edit(Swiper $swiper)
    {
        return $swiper;
    }

    public function update(Request $request, Swiper $swiper)
    {
        $request->validate([
            'title' => ['required'],
            'image' => ['required'],
            'url' => ['required'],
        ], [
            'title.required' => '请输入标题',
            'image.required' => '请上传图片',
            'url.required' => '请输入跳转链接'
        ]);
        $swiper->update($request->input());
        return $this->message('修改成功');
    }

    public function destroy(Swiper $swiper)
    {
        $swiper->delete();
        return $this->message('删除成功');
    }
}
